package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.EditFlightView;
import group2assignone.view.manager.ManagerView;

/**
 * Use Case: Edit Flight                                                    <br>
 * Pre-Condition: Manager inputs flight details and selects 'Done'          <br>
 * from the edit flight view                                                <br>
 * Post-Condition: UI is updated                                            <br>
 * 1. System retrieves the new flight details.                              <br>
 * 2. System updates flight.                                                <br>
 * 3. System updates UI to the manager main menu.                           <br>
 *
 * @author group2
 */
public class UCEditFlight implements UCController {

    private EditFlightView editView = new EditFlightView();
    private Flight f;// = new Flight();

    /**
     * sets view and flight
     * @param eView
     * @param flight
     */
    public UCEditFlight(EditFlightView eView, Flight flight) {
        editView = eView;
        f = flight;

    }
    
    /**
     *Use Case Controller - allows the manager to edit a flight
     */
    @Override
    public void run() {
        //1. System retrieves the new flight details.
        editView.loadDetails(f);
        //2. System updates flight.
        MyDAO coms = UCStartup.getInstance().getDAO();
        coms.sQLEditFlight(f, editView.getOldFlightNum());
        //3. System updates UI to the manager main menu.
        editView.dispose();
        ManagerView mv = ManagerView.getInstance();
        mv.go();
    }
}
